package com.lzw.controller.admin;

import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.lzw.anno.Log;
import com.lzw.pojo.StockEntries;
import com.lzw.service.admin.StockMange2Service;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.format.annotation.DateTimeFormat;
import org.springframework.web.bind.annotation.*;

import java.time.LocalDate;
import java.util.List;

@CrossOrigin(origins = "http://localhost:7070")
@RestController
@RequestMapping("/StockManege2")
public class StockMange2 {

    @Autowired
    private StockMange2Service stockMange2Service;

    @GetMapping("/list")
    public PageInfo<StockEntries> list(
            @RequestParam(defaultValue = "1") Integer pageNum,
            @RequestParam(defaultValue = "10") Integer pageSize,
            @DateTimeFormat(pattern = "yyyy-MM-dd") LocalDate entryDate,
            String medicine, String supplier){
        PageHelper.startPage(pageNum,pageSize);
        List<StockEntries> list = stockMange2Service.list(pageNum, pageSize, medicine, entryDate, supplier);
        return new PageInfo<>(list);
    }

    //批量删除
    @Log
    @DeleteMapping("/delete/{ids}")
    public String delete(@PathVariable List<Integer> ids){
        stockMange2Service.delete(ids);
        return "删除成功";
    }

    //添加
    @Log
    @PostMapping("/add")
    public String add(@RequestBody StockEntries stockEntries) {
        stockMange2Service.add(stockEntries);
        return "添加成功";
    }

    //更新
    @Log
    @PutMapping("/update")
    public String update(@RequestBody StockEntries stockEntries){
        stockMange2Service.update(stockEntries);
        return "更新成功";
    }
}
